include("shared.lua");
AddCSLuaFile("cl_init.lua");
AddCSLuaFile("shared.lua");
-- Setting up all the different properties of our melon.
ENT.Delay = 1.4;
ENT.Healthlol = 30;
ENT.FiringRange = 350;
ENT.NoMoveRange = 20;
ENT.DeathRadius = 20;
ENT.DeathMagnitude = 5;
ENT.MovingForce = 25;
ENT.MelonModel = "models/props_junk/watermelon01.mdl";

-- Now we tell the base class to set up the melon. Pay attention - the variables must be defined BEFORE calling Setup().
function ENT:Initialize()
	self:Setup();
	--What is this? We're overriding the colours too?
	if (self.Team == 1) then
		self.Entity:SetColor (255, 128, 128, 255);
	end
	if (self.Team == 2) then
		self.Entity:SetColor (128, 128, 255, 255);
	end
	if (self.Team == 3) then
		self.Entity:SetColor (128, 255, 128, 255);
	end
	if (self.Team == 4) then
		self.Entity:SetColor (255, 255, 128, 255);
	end
	if (self.Team == 5) then
		self.Entity:SetColor (255, 128, 255, 255);
	end
	if (self.Team == 6) then
		self.Entity:SetColor (128, 255, 255, 255);
	end
if !self.Grav then 
self.MovingForce = (self.MovingForce * server_settings.Int( "WM_Flyingspeed", 0.75))
end
end

--No attacking or other thoughts function - this is a special warmelon, and as such, we want to override Think().
function ENT:DoAttacks ()
	local entz = ents.FindByClass("info_target");
	for k, v in pairs(entz) do
		if v.Warmelon then
		local Heal = 1;
			local traceRes=util.QuickTrace (self.Entity:GetPos(), v:GetParent():GetPos()-self.Entity:GetPos(), self.Entity);
			if (v:GetPos():Distance(self.Entity:GetPos())<self.FiringRange && v:GetParent():GetTable().Team == self.Team) then
			 if (v:GetParent():GetTable().Healthlol ~= nil && v:GetParent():GetTable().Maxlol ~= nil && v:GetParent():GetTable().Healthlol < v:GetParent():GetTable().Maxlol && traceRes.Entity == v:GetParent()) then
        v:GetParent():GetTable().Healthlol = v:GetParent():GetTable().Healthlol+4;
			 elseif (v:GetParent():GetTable().health ~= nil && v:GetParent():GetTable().maxhealth ~= nil && v:GetParent():GetTable().health < v:GetParent():GetTable().maxhealth && traceRes.Entity == v:GetParent()) then
          v:GetParent():GetTable().health = v:GetParent():GetTable().health + 4;
            if v:GetParent():GetTable().health > (v:GetParent():GetTable().maxhealth * 0.5) then
            v:GetParent():SetColor()
  if (v.Team == 1) then
		v:GetParent():SetColor (255, 0, 0, 255);
	end
	if (v.Team == 2) then
		v:GetParent():SetColor (0, 0, 255, 255);
	end
	if (v.Team == 3) then
		v:GetParent():SetColor (0, 255, 0, 255);
	end
	if (v.Team == 4) then
		v:GetParent():SetColor (255, 255, 0, 255);
	end
	if (v.Team == 5) then
		v:GetParent():SetColor (255, 0, 255, 255);
	end
	if (v.Team == 6) then
		v:GetParent():SetColor (0, 255, 255, 255);
	end
	end
       elseif (v:GetParent():GetTable().breakable ~= nil && v:GetParent():GetTable().breakable.Cur < v:GetParent():GetTable().breakable.Max && traceRes.Entity == v:GetParent()) then
          v:GetParent():GetTable().breakable.Cur = v:GetParent():GetTable().breakable.Cur + 4;
       else
       Heal = 0;
       end
      else Heal = 0;
      end
      if Heal == 1 then
          local angle = v:GetParent():GetPos() - self.Entity:GetPos();
          if (self.LOLFX == true) then
						local fx = EffectData();
						fx:SetOrigin(v:GetPos());
						util.Effect("johnny_healing", fx);
          end
		local fx2 = EffectData();
		fx2:SetOrigin(self.Entity:GetPos());
		fx2:SetStart(v:GetParent():GetPos());
	if (self.Team == 1) then
		util.Effect("johnny_redlaser", fx2);
	elseif (self.Team == 2) then
		util.Effect("johnny_bluelaser", fx2);
	elseif (self.Team == 3) then
		util.Effect("johnny_greenlaser", fx2);
	elseif (self.Team == 4) then
		util.Effect("johnny_yellowlaser", fx2);
	elseif (self.Team == 5) then
		util.Effect("johnny_magentalaser", fx2);
	elseif (self.Team == 6) then
		util.Effect("johnny_cyanlaser", fx2);
	else
		util.Effect("johnny_redlaser", fx2);
	end
		local fxx = EffectData();
		fxx:SetOrigin(self.Entity:GetPos());
		fxx:SetAngle(angle:Angle());
		fxx:SetScale(1.2);
		util.Effect("MuzzleEffect", fxx);
					if (v:GetParent():GetTable().Healthlol ~= nil && v:GetParent():GetTable().Healthlol>v:GetParent():GetTable().Maxlol/5 && v:GetParent():GetTable().trail) then
						v:GetParent():GetTable().trail:Remove();
						v:GetParent():GetTable().trail = nil;
					end
break;
end
			end
		end
	end
